package org.tcs.com.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.LocalDateTime;

@Entity
@Table(name = "USERS")
public class User {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "USER_ID")
	private long id;

	private String name;
	private String userName;
	private String email;
	private String password;
	private boolean sendEmail;
	private boolean active;
	/*
	 * Use for password encryption 
	 * Refer:https://www.owasp.org/index.php/Hashing_Java
	 */
	private String salt;

	@ManyToMany(cascade = { CascadeType.ALL })
	@JoinTable(name = "USER_GROUP", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "GROUP_ID") })
	private Set<Group> userGroups = new HashSet<Group>();

	@Column(name = "REGISTRATION_DATE")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
	private LocalDateTime registerationDate;

	@Column(name = "LAST_VISITED_DATE")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
	private LocalDateTime lastVisitedDate;
	
	@OneToMany(mappedBy="assignedTo",cascade = {CascadeType.ALL})
	private List<Incident> incidents = new ArrayList<Incident>();

	public List<Incident> getIncidents() {
		return incidents;
	}

	public void setIncidents(List<Incident> incidents) {
		this.incidents = incidents;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public boolean isSendEmail() {
		return sendEmail;
	}

	public void setSendEmail(boolean sendEmail) {
		this.sendEmail = sendEmail;
	}

	public Set<Group> getUserGroups() {
		return userGroups;
	}

	public void setUserGroups(Set<Group> userGroups) {
		this.userGroups = userGroups;
	}

	public LocalDateTime getRegisterationDate() {
		return registerationDate;
	}

	public void setRegisterationDate(LocalDateTime registerationDate) {
		this.registerationDate = registerationDate;
	}

	public LocalDateTime getLastVisitedDate() {
		return lastVisitedDate;
	}

	public void setLastVisitedDate(LocalDateTime lastVisitedDate) {
		this.lastVisitedDate = lastVisitedDate;
	}

}
